package com.lx.note.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * User: Administrator
 * Date: 2018/06/04 下午 9:28
 */

@Component
@Aspect
public class AroundAspect {

    @Around("bean(userService)")
    public Object test(ProceedingJoinPoint jp) throws Throwable{
        try{
            System.out.println("业务方法之前");
            //调用目标的业务方法 (利用反射实现invoke())
            Object val = jp.proceed();
            //业务执行方法之后
            System.out.println("业务执行方法之后");
            return val;
        }catch (Throwable e) {
            System.out.println("业务方法出现异常");
            e.printStackTrace();
            throw e;
        }finally {
            System.out.println("finally业务方法之后");
        }
    }


}
